package co.edu.militar.multimedia.admin;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author Alejandro
 */
public class ArbolManager {

    //create the root node
    private DefaultMutableTreeNode root;

    public ArbolManager() {
        root = new DefaultMutableTreeNode("Raiz");
    }

    public void addNodo(String fileName, JTree tree) {
        DefaultMutableTreeNode nodo = new DefaultMutableTreeNode(fileName);
        root.add(nodo);
        DefaultTreeModel node = (DefaultTreeModel) tree.getModel();
        node.reload();
    }

    public void deleteNodo(DefaultMutableTreeNode nodo, JTree tree) {
        DefaultTreeModel node = (DefaultTreeModel) tree.getModel();
        node.removeNodeFromParent(nodo);
        node.reload();
    }

    public void limpiarNodo(JTree tree) {
        DefaultTreeModel node = (DefaultTreeModel) tree.getModel();
        root = new DefaultMutableTreeNode("Raiz");
        node.setRoot(root);
        node.reload();
    }

    public DefaultMutableTreeNode getRoot() {
        return root;
    }

    public void setRoot(DefaultMutableTreeNode root) {
        this.root = root;
    }
}
